package com.isay.app.honey.ui.cash;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.isay.app.honey.R;
import com.isay.app.honey.manager.NetworkManager;
import com.isay.frameworklib.okhttp.ICommonCallback;
import com.isay.frameworklib.ui.BaseActivity;
import com.isay.frameworklib.utils.ToastUtils;

/**
 * 我的账号
 */
public class BankCodeActivity extends BaseActivity implements View.OnClickListener {


    private EditText mEdtBankCode;
    private EditText mEdtBankName;
    private static final int REQUEST_CODE = 200;

    public static void launch(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, BankCodeActivity.class);
        ((Activity) context).startActivityForResult(intent, REQUEST_CODE);
    }

    @Override
    protected void onCreateActivity(Bundle savedInstanceState) {
        setContentView(R.layout.activity_account);
        initView();
    }

    @Override
    protected int getStatusBarColor() {
        return R.color.white;
    }


    private void initView() {
        ((TextView) findViewById(R.id.tv_title)).setText("我的账号");
        findViewById(R.id.iv_go_back).setOnClickListener(this);
        findViewById(R.id.tv_commit_bank_code).setOnClickListener(this);
        mEdtBankCode = findViewById(R.id.edt_bank_code);
        mEdtBankName = findViewById(R.id.edt_bank_name);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_go_back:
                finish();
                break;
            case R.id.tv_commit_bank_code:
                setBankCode();
                break;
            default:
                break;
        }
    }


    private void setBankCode() {
        final String name = mEdtBankName.getText().toString().trim();
        final String code = mEdtBankCode.getText().toString().trim();
        NetworkManager.setBankCode(name, code, new ICommonCallback() {
            @Override
            public void onSuccess(int ret, String msg, String content) {
                ToastUtils.show(msg);
                if (ret == 200) {
                    Intent intent = new Intent();
                    intent.putExtra("name", name);
                    intent.putExtra("bankcode", code);
                    setResult(REQUEST_CODE, intent);
                    finish();
                }
            }

            @Override
            public void onFailure(Exception e) {

            }
        });
    }

}
